
private ["_ctrl","_ok","_units","_index","_XD_display","_children","_nb","_entry_side","_side_name","_side_displayName","_side","_entry_faction","_faction_name","_faction_displayName","_nb_groups","_entry_group"
		,"_group_name","_group_displayName","_arr","_nb_child","_entry_u_group","_u_group_name","_u_group_displayName","_arr2"];
if (!X_Client) exitWith {};

_ctrl_idx = _this select 1;

disableSerialization;

_XD_display = uiNameSpace getVariable "X_AI_GROUP_DIALOG";

if (isnil "_XD_display") exitWith{};
if (isnull _XD_display) exitWith{};

_ctrl_faction = _XD_display displayCtrl 23003; // Faction Combo
_ctrl_group = _XD_display displayCtrl 23006; // Group Combo
_ctrl_unit = _XD_display displayCtrl 23009; // Unit Combo

_faction_index = lbCurSel _ctrl_faction;
_group_index = lbCurSel _ctrl_group;
_unit_index = lbCurSel _ctrl_unit;

diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"groupselchanged.sqf","Start",[_ctrl_idx, _faction_index, _group_index , _unit_index]];

switch (_ctrl_idx) do {
	case 0: { // Changed Faction
		lbClear _ctrl_group;
		if (_faction_index >= 0) then {
			_group_list = (SIDE_AI_GROUP_ARRAY select _faction_index) select 5;
			diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"groupselchanged.sqf","FactionChanged",_group_list];
			{
				_group_displayName = _x select 4;
				_ctrl_group lbAdd _group_displayName;
			} forEach _group_list;
			_ctrl_group lbSetCurSel 0;
		};
	};
	case 1: { // Changed Group
		lbClear _ctrl_unit;
		if (_faction_index >= 0 && _group_index >= 0) then {
			_group_list = (SIDE_AI_GROUP_ARRAY select _faction_index) select 5;
			_unit_list = (_group_list select _group_index) select 5;
			diag_log Format["(%1)[%2]: %3: %4",diag_tickTime,"groupselchanged.sqf","GroupChanged",_unit_list];
			{
				_unit_class = _x select 5;
				_unit_displayName = _unit_class select 4;
				_ctrl_unit lbAdd _unit_displayName;
			} forEach _unit_list;
			_ctrl_unit lbSetCurSel 0;
		};
	};
	case 2: { // Changed Unit
		
	};
};